#include <bits/stdc++.h>
#define re register
#define fst first
#define snd second
#define int long long

using namespace std;

typedef pair<int,int> pii;
const int N = 3010;
int n,m; char arr[N][N];
int sum[N],cnt1[N][N],cnt2[N][N];
int L[N][N],R[N][N],U[N][N],D[N][N];

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

inline int dfs(int ln,int rn,int lm,int rm){
    if (ln >= rn || lm >= rm) return 0;
    int res = 0;
    if (rn - ln <= rm - lm){
        int mid = (lm + rm) / 2;
        for (re int i = ln;i <= rn;i++){
            for (re int j = ln;j <= rn;j++) cnt1[i][j] = cnt2[i][j] = 0;
        }
        for (re int i = ln;i <= rn;i++){
            fill(sum + ln - 1,sum + rn + 2,0);
            for (re int j = max(lm,L[i][mid]);j <= mid;j++) sum[min(rn,D[i][j])]++;
            for (re int j = ln;j <= rn;j++) sum[j] += sum[j - 1];
            for (re int j = i + 1;j <= rn;j++){
                if (arr[i][mid] == arr[j][mid] && L[i][mid] >= L[j][mid]) cnt1[i][j] = sum[rn] - sum[j - 1];
            }
        }
        for (re int i = ln;i <= rn;i++){
            fill(sum + ln - 1,sum + rn + 2,0);
            for (re int j = max(lm,L[i][mid]);j <= mid;j++) sum[max(ln,U[i][j])]++;
            for (re int j = ln;j <= rn;j++) sum[j] += sum[j - 1];
            for (re int j = ln;j < i;j++){
                if (arr[i][mid] == arr[j][mid] && L[i][mid] > L[j][mid]) cnt1[j][i] = sum[j];
            }
        }
        for (re int i = ln;i <= rn;i++){
            fill(sum + ln - 1,sum + rn + 2,0);
            for (re int j = mid + 1;j <= min(rm,R[i][mid]);j++) sum[min(rn,D[i][j])]++;
            for (re int j = ln;j <= rn;j++) sum[j] += sum[j - 1];
            for (re int j = i + 1;j <= rn;j++){
                if (arr[i][mid] == arr[j][mid] && R[i][mid] <= R[j][mid]) cnt2[i][j] = sum[rn] - sum[j - 1];
            }
        }
        for (re int i = ln;i <= rn;i++){
            fill(sum + ln - 1,sum + rn + 2,0);
            for (re int j = mid + 1;j <= min(rm,R[i][mid]);j++) sum[max(ln,U[i][j])]++;
            for (re int j = ln;j <= rn;j++) sum[j] += sum[j - 1];
            for (re int j = ln;j < i;j++){
                if (arr[i][mid] == arr[j][mid] && R[i][mid] < R[j][mid]) cnt2[j][i] = sum[j];
            }
        }
        for (re int i = ln;i <= rn;i++){
            for (re int j = i + 1;j <= rn;j++) res += (cnt1[i][j] * cnt2[i][j]);
        } res += (dfs(ln,rn,lm,mid) + dfs(ln,rn,mid + 1,rm));
    }
    else{
        int mid = (ln + rn) / 2;
        for (re int i = lm;i <= rm;i++){
            for (re int j = lm;j <= rm;j++) cnt1[i][j] = cnt2[i][j] = 0;
        }
        for (re int i = lm;i <= rm;i++){
            fill(sum + lm - 1,sum + rm + 2,0);
            for (re int j = max(ln,U[mid][i]);j <= mid;j++) sum[min(rm,R[j][i])]++;
            for (re int j = lm;j <= rm;j++) sum[j] += sum[j - 1];
            for (re int j = i + 1;j <= rm;j++){
                if (arr[mid][i] == arr[mid][j] && U[mid][i] >= U[mid][j]) cnt1[i][j] = sum[rm] - sum[j - 1];
            }
        }
        for (re int i = lm;i <= rm;i++){
            fill(sum + lm - 1,sum + rm + 2,0);
            for (re int j = max(ln,U[mid][i]);j <= mid;j++) sum[max(lm,L[j][i])]++;
            for (re int j = lm;j <= rm;j++) sum[j] += sum[j - 1];
            for (re int j = lm;j < i;j++){
                if (arr[mid][i] == arr[mid][j] && U[mid][i] > U[mid][j]) cnt1[j][i] = sum[j];
            }
        }
        for (re int i = lm;i <= rm;i++){
            fill(sum + lm - 1,sum + rm + 2,0);
            for (re int j = mid + 1;j <= min(rn,D[mid][i]);j++) sum[min(rm,R[j][i])]++;
            for (re int j = lm;j <= rm;j++) sum[j] += sum[j - 1];
            for (re int j = i + 1;j <= rm;j++){
                if (arr[mid][i] == arr[mid][j] && D[mid][i] <= D[mid][j]) cnt2[i][j] = sum[rm] - sum[j - 1];
            }
        }
        for (re int i = lm;i <= rm;i++){
            fill(sum + lm - 1,sum + rm + 2,0);
            for (re int j = mid + 1;j <= min(rn,D[mid][i]);j++) sum[max(lm,L[j][i])]++;
            for (re int j = lm;j <= rm;j++) sum[j] += sum[j - 1];
            for (re int j = lm;j < i;j++){
                if (arr[mid][i] == arr[mid][j] && D[mid][i] < D[mid][j]) cnt2[j][i] = sum[j];
            }
        }
        for (re int i = lm;i <= rm;i++){
            for (re int j = i + 1;j <= rm;j++) res += (cnt1[i][j] * cnt2[i][j]);
        } res += (dfs(ln,mid,lm,rm) + dfs(mid + 1,rn,lm,rm));
    } return res;
}

signed main(){
    freopen("star.in","r",stdin);
    freopen("star.out","w",stdout);
    n = read(),m = read();
    for (re int i = 1;i <= n;i++) scanf("%s",arr[i] + 1);
    for (re int i = 1;i <= n;i++){
        for (re int j = 1;j <= m;j++) L[i][j] = ((arr[i][j] == arr[i][j - 1]) ? L[i][j - 1] : j);
    }
    for (re int i = 1;i <= n;i++){
        for (re int j = m;j;j--) R[i][j] = ((arr[i][j] == arr[i][j + 1]) ? R[i][j + 1] : j);
    }
    for (re int i = 1;i <= n;i++){
        for (re int j = 1;j <= m;j++) U[i][j] = ((arr[i][j] == arr[i - 1][j]) ? U[i - 1][j] : i);
    }
    for (re int i = n;i;i--){
        for (re int j = 1;j <= m;j++) D[i][j] = ((arr[i][j] == arr[i + 1][j]) ? D[i + 1][j] : i);
    } printf("%lld",dfs(1,n,1,m));
    return 0;
}